package com.easylinkin.linkappapi.common.exceptions;

import java.util.Collection;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

/**
 * <p>
 * 系统内部断言，为了能抛出系统内的异常枚举
 * </p>
 *
 * @author TongJie
 * @since 2021/1/8 11:31
 */
public class SimpleAssert extends Assert {


    public static void isTrue(boolean expression, StandardException standardException) {
        if (!expression) {
            throw new BusinessException(standardException);
        }
    }

    public static void notNull(@Nullable Object object, StandardException standardException) {
        if (object == null) {
            throw new BusinessException(standardException);
        }
    }

    public static void notEmpty(@Nullable Collection<?> collection, StandardException standardException) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new BusinessException(standardException);
        }
    }

}
